home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1842 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: easy.in-chemnitz.de!mkmk!floh
  2. From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Redirecting
  5. Message-ID: <u6j+x*-D0@mkmk.in-chemnitz.de>
  6. Date: Tue, 23 Jan 1996 23:34:54 CET
  7. Reply-To: floh@mkmk.in-chemnitz.de
  8. References: <9601231531.AA0006s@cliffe.demon.co.uk>
  9. Distribution: world
  10. Organization: private uucp site
  11. X-Newsreader: Arn V 1.04
  12.  
  13. In article <9601231531.AA0006s@cliffe.demon.co.uk>, Steven Chapman writes:
  14.  
  15. > Thanks for the previous help 
  16. > What i now need is how to declare BPTR so i can use the file it opens
  17. > globally thoughtout my program.
  18. > As i can only use this within the same { }.
  19. >  BPTR       fh;
  20. >  if(!(fh = Open("t:WBtest",MODE_NEWFILE)))
  21.  
  22. Create a set of routines that accept your file handle as
  23. input argument and make sure to call them only when
  24. the filehandle is valid:
  25.  
  26. /*** writes "This" to file fh ***/
  27. BOOL WriteThis(BPTR fh)
  28. {
  29.     UBYTE *str = "This\n";
  30.     if (Write(fh, str, strlen(str)) > 0) return(TRUE);
  31.     else return(FALSE);
  32. }
  33.  
  34. /*** writes "That" to file fh ***/
  35. BOOL WriteThat(BPTR fh)
  36. {
  37.     /* ... */
  38. }
  39.  
  40. /*** creates a file with "This" and "That" in it ***/
  41. BOOL CreateFile(UBYTE *filename)
  42. {
  43.  
  44.     BPTR fh;
  45.     BOOL success = FALSE;
  46.  
  47.     if (fh = Open(filename, MODE_NEWFILE)) {
  48.         if(WriteThis(file)) {
  49.             if (WriteThat(file)) {
  50.                 success = TRUE;
  51.             };
  52.         };
  53.         Close(fh);
  54.     };
  55.     return(success);
  56. }
  57.  
  58. Please do not use a global variable for the filehandle 
  59. in such situations, as this will lead to certain confusion
  60. with more than 10*n functions spread over n source files.
  61.  
  62. In two words: globals suck.
  63.  
  64. ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
  65. ...// Sep'95: Return Of The Living Death...................
  66. \\// 90% of everything is crap (Sturgeon's Law)...........
  67. =\\===============================================Amiga!=
  68.  
  69.